package com.loby.data.handler;

import com.loby.data.emun.TableType;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class TableTypeHandler extends BaseTypeHandler<TableType> {
    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, TableType tableType, JdbcType jdbcType) throws SQLException {
        preparedStatement.setInt(i,tableType.getVal());
    }

    @Override
    public TableType getNullableResult(ResultSet resultSet, String columnName) throws SQLException {
        return TableType.valueOf(resultSet.getInt(columnName));
    }

    @Override
    public TableType getNullableResult(ResultSet resultSet, int i) throws SQLException {
        return TableType.valueOf(resultSet.getInt(i));
    }

    @Override
    public TableType getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        return TableType.valueOf(callableStatement.getInt(i));
    }



}
